<?php

namespace app\index\service;

use app\common\model\Trade;
use app\index\dao\TradeDao;
use app\index\model\UM as UM;
use think\Collection;

/**
 * Class OrderService
 * @package app\index\service
 */
class OrderService
{
    // dao
    private TradeDao $tradeDao;

    public function __construct(TradeDao $tradeDao)
    {
        $this->tradeDao = $tradeDao;
    }

    /**
     * 列表
     * @param UM|null $user
     * @param int|null $page
     * @param int|null $page_size
     * @return Collection
     */
    public function index(UM $user, $status, ?int $page = null, ?int $page_size = null): Collection
    {
        $memberId = $user->id;

        return $this->tradeDao->selectMyTrades($memberId, $status, $page, $page_size);
    }

    /**
     * 查询
     * @param UM|null $user
     * @param int $id
     * @return Trade
     */
    public function read(?UM $user, int $id): ?Trade
    {
        //这里如果要修改查询，建议把查询放到dao层去
        return $this->tradeDao->findByPK($id, true);
    }

}
